package com.company.design.action.observer;


import java.util.Enumeration;
import java.util.Vector;

/**
 * @author yingfing
 * @create 2020--09--24 8:14
 * @describe
 */
public abstract class AbstractSubject implements Subject {

    private Vector<Observer> vector = new Vector<>();

    @Override
    public void add(Observer observer) {
        vector.add(observer);
    }

    @Override
    public void del(Observer observer) {
        vector.remove(observer);
    }

    @Override
    public void notifyObservers() {
        Enumeration<Observer> elements = vector.elements();
        while (elements.hasMoreElements()) {
            Observer observer = elements.nextElement();
            observer.update();
        }
    }
}
